<?php

/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: admincp_album.php 27892 2012-02-16 07:24:19Z chenmengshu $
 */
if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}
include_once libfile('function/portalcp');

cpheader();
echo '<script type="text/javascript" src="static/js/calendar.js"></script>';
$fileSetting		= array(
	'image/pjpeg'	=> 'jpg',
	'image/jpeg'	=> 'jpg',
	'image/bmp'		=> 'bmp',
	'image/gif'		=> 'gif',
	'image/x-png'	=> 'png',
	'image/png'		=> 'png',
);
$opts				= array( 'master', 'work', 'message' );
$opt				= in_array( $_GET['operation'], $opts ) ? $_GET['operation'] : array_shift( $opts );
if( $opt == 'master' ){
	$dos		= array( 'list', 'add', 'del', 'mod' );
	$do			= in_array( $_GET['do'], $dos ) ? $_GET['do'] : array_shift( $opts );
	if( $do == 'list' ){
		showsubmenu( '玉雕名家资料', array(
			array( '资料列表', 'master&operation=master&do=list', 1 ),
			array( '添加', 'master&operation=master&do=add', 0 )
		));

		if( submitcheck( 'ordersubmit' ) ){
			foreach( $_GET['order'] as $_id => $level ){
				C::t( 'master_main' )->update( $_id, array( 'level' => intval( $level ) ) );
			}
		}
		showtableheader();
		showformheader( "master&operation=master&do=list" );
		echo '<div style="height:30px;line-height:30px;">
				姓名 <input class="txt" type="text" value="'.$_GET['name'].'" name="name" />  
				级别 <input class="txt" type="text" value="'.$_GET['level'].'" name="level" />
				<input type="submit" class="btn" value="'.cplang('search').'" onclick="return srchforum()" /></div>';
		showformfooter();
		showtablefooter();

		showtableheader();

		showformheader( "master&operation=master&do=list" );
		$_GET['page']	= $_GET['page'] ? $_GET['page'] : 1;
		$limit			= 10;
		$s_limit		= ( $_GET['page'] - 1 ) * $limit . ", {$limit}";
		$where			= "";
		$where			.= empty( $_GET['name'] ) ? '' : "`a`.`name` LIKE '%{$_GET['name']}%'";
		$where			.= empty( $_GET['level'] ) ? '' : "`a`.`level` = '{$_GET['level']}'";
		$memberLs		= C::t( 'master_main' )->fetch_all( $where, $s_limit, "`a`.`level` DESC, `a`.`id`" );
		$page			= multi( $memberLs['num'], $limit, $_GET['page'], ADMINSCRIPT."?action=master&operation=master&do=list" );

		showsubtitle( array( '排序', '姓名', '级别', '绑定用户', '头衔', 'admin' ) );
		foreach( $memberLs['list'] as $info ){
			showtablerow( '', '', array(
				"<input style='width:20px;' type='text' name='order[{$info['id']}]' value='{$info['level']}' />",
				"<a href='./master.php?id={$info['id']}' target='blank'>{$info['name']}</a>",
				$info['level'],
				empty( $info['uid'] ) ? '-' : "<a href='home.php?mod=space&uid={$info['uid']}' target='_blank'>{$info['username']}</a>",
				$info['title'],
				"<a href=\"".ADMINSCRIPT."?action=master&operation=master&do=mod&id={$info['id']}\">$lang[edit]</a>&nbsp;" . 
				"<a href=\"".ADMINSCRIPT."?action=master&operation=work&do=list&mid={$info['id']}\">作品</a>&nbsp;" . 
				"<a href=\"".ADMINSCRIPT."?action=master&operation=message&do=list&mid={$info['id']}\">文章</a>&nbsp;" .
				"<a href='#' onclick=\"if( window.confirm( '您是否确认要删除玉雕大师信息？' ) )window.location='".ADMINSCRIPT."?action=master&operation=master&do=del&mid={$info['id']}';\">删除</a>"
			));
		}
		showsubmit( 'ordersubmit' );
		showformfooter();
		showtablefooter();
		showtableheader();
		showtablerow( '', array( 'class="infobox"', 'class="infobox"' ), array( '', $page ) );
		showtablefooter();
	}elseif( $do == 'add' ){
		if( !submitcheck( 'addsubmit' ) ){
			showsubmenu( '玉雕名家资料', array(
				array( '资料列表', "master&operation=master&do=list&mid={$info['id']}", 0 ),
				array( '添加', "master&operation=master&do=add&mid={$info['id']}", 1 )
			));

			showformheader( 'master&operation=master&do=add', 'enctype' );
			showtableheader( '新建名家资料' );

			showsetting( '姓名', 'name', '', 'text');
			showsetting( '头衔', 'title', '', 'text');
			showsetting( '级别', 'level', '', 'text' );
			showsetting( '绑定用户', 'uid', '', 'number');
			showsetting( '照片', 'photo', '', 'file');
			showsetting( '性别', '', '', "<select name='sex' style='width:80px'><option value='1'>男</option><option value='2'>女</option></select>");
			showsetting( '出生日期', 'birth', '', 'calendar' );
			showsetting( '祖籍', 'hometown', '', 'text' );
			showsetting( '擅长领域', 'field', '', 'text' );
			showsetting( '擅长材质', 'material', '', 'text' );

			showsetting( '人生格言', 'maxim', '', 'textarea' );
			showsetting( '个人经历', 'history', '', 'textarea' );
			showsetting( '个人简介', 'desc', '', 'textarea' );
			showsubmit( 'addsubmit' );
			showtablefooter();
			showformfooter();
		}else{
			$data			= array(
				'name'		=> $_GET['name'],
				'title'		=> $_GET['title'],
				'level'		=> $_GET['level'],
				'uid'		=> $_GET['uid'],
				'sex'		=> $_GET['sex'],
				'birth'		=> $_GET['birth'],
				'hometown'	=> $_GET['hometown'],
				'field'		=> $_GET['field'],
				'material'	=> $_GET['material'],
				'maxim'		=> $_GET['maxim'],
				'history'	=> $_GET['history'],
				'desc'		=> $_GET['desc'],
			);
			if( empty( $data['name'] ) )
				cpmsg( '请输入姓名', '', 'error' );
			if( !empty( $_FILES['photo'] ) && $_FILES['photo']['size'] > 0 ){
				if( !isset( $fileSetting[$_FILES['photo']['type']] ) )
					cpmsg( '不支持此类图片类型', '', 'error' );
				$_fileName	= md5( time() ) . ".{$fileSetting[$_FILES['photo']['type']]}";
				$_aimPath	= "{$_G['setting']['attachdir']}master/{$_fileName}";
				
				if( copy( $_FILES['photo']['tmp_name'], $_aimPath ) )
					$data['photo']	= "data/attachment/master/{$_fileName}";
			}
			$id			= C::t( 'master_main' )->insert( $data, true );
			cpmsg( '添加成功', 'action=master&operation=master&do=list', 'succeed' );
		}
	}elseif( $do == 'mod' ){
		if( !submitcheck( 'editsubmit' ) ){
			$master				= C::t( 'master_main' )->fetch( $_GET['id'] );
			if( !$master ){
				cpmsg('您选择的内容不存在', '', 'error');
			}

			showsubmenu( '玉雕名家资料', array(
				array( '资料列表', 'master&operation=master&do=list', 0 ),
				array( '添加', 'master&operation=master&do=mod', 0 )
			));

			showformheader( "master&operation=master&do=mod&id={$_GET['id']}", 'enctype' );
			showtableheader( '修改名家资料' );

			showsetting( '姓名', 'name', $master['name'], 'text');
			showsetting( '头衔', 'title', $master['title'], 'text');
			showsetting( '级别', 'level', $master['level'], 'text' );
			showsetting( '绑定用户', 'uid', $master['uid'], 'number');
			if( !empty( $master['photo'] ) )
				showsetting( '', '', '', "<img src='{$master['photo']}' style='height:50px;' />" );
			showsetting( '照片', 'photo', '', 'file' );
			showsetting( '性别', '', '', "<select name='sex' style='width:80px'><option value='1'>男</option><option value='2' ".( $master['sex'] == '2' ? 'selected' : '' ).">女</option></select>");
			showsetting( '出生日期', 'birth', $master['birth'], 'calendar' );
			showsetting( '祖籍', 'hometown', $master['hometown'], 'text' );
			showsetting( '擅长领域', 'field', $master['field'], 'text' );
			showsetting( '擅长材质', 'material', $master['material'], 'text' );

			showsetting( '人生格言', 'maxim', $master['maxim'], 'textarea' );
			showsetting( '个人经历', 'history', $master['history'], 'textarea' );
			showsetting( '个人简介', 'desc', $master['desc'], 'textarea' );
			showsubmit( 'editsubmit' );
			showtablefooter();
			showformfooter();
		}else{
			$_G['setting']['attachdir'];
			$data			= array(
				'name'		=> $_GET['name'],
				'title'		=> $_GET['title'],
				'level'		=> $_GET['level'],
				'uid'		=> $_GET['uid'],
				'sex'		=> $_GET['sex'],
				'birth'		=> $_GET['birth'],
				'hometown'	=> $_GET['hometown'],
				'field'		=> $_GET['field'],
				'material'	=> $_GET['material'],
				'maxim'		=> $_GET['maxim'],
				'history'	=> $_GET['history'],
				'desc'		=> $_GET['desc'],
			);
			if( empty( $data['name'] ) )
				cpmsg( '请输入姓名', '', 'error' );
			if( !empty( $_FILES['photo'] ) && $_FILES['photo']['size'] > 0 ){
				if( !isset( $fileSetting[$_FILES['photo']['type']] ) )
					cpmsg( '不支持此类图片类型', '', 'error' );
				$_fileName	= md5( time() ) . ".{$fileSetting[$_FILES['photo']['type']]}";
				$_aimPath	= "{$_G['setting']['attachdir']}master/{$_fileName}";
				
				if( copy( $_FILES['photo']['tmp_name'], $_aimPath ) )
					$data['photo']	= "data/attachment/master/{$_fileName}";
			}
			C::t( 'master_main' )->update( $_GET['id'], $data );
			cpmsg( '修改成功', 'action=master&operation=master&do=list', 'succeed' );
		}
	}elseif( $do == 'del' ){
		if( empty( $_GET['mid'] ) ){
			cpmsg( '请输选择要删除的玉雕大师', '', 'error' );
		}
		C::t( 'master_main' )->delete( $_GET['mid'] );
		cpmsg( '删除成功', 'action=master&operation=master&do=list' );
		echo 123;exit;
	}
}elseif( $opt == 'work' ){
	$dos		= array( 'list', 'add', 'del', 'mod' );
	$do			= in_array( $_GET['do'], $dos ) ? $_GET['do'] : array_shift( $opts );
	$mid		= $_GET['mid'];
	showsubmenu( '玉雕名家作品管理', array(
		array( '作品列表', "master&operation=work&do=list&mid={$mid}", 1 ),
		array( '添加作品', "master&operation=work&do=add&mid={$mid}", 0, 1 )
	));
	if( empty( $mid ) ){
		showtableheader();
		showformheader( "master&operation=work&do={$do}" );
		echo '<div style="height:30px;line-height:30px;">
				编号 <input class="txt" type="text" value="'.$_GET['name'].'" name="mid" />
				<input type="submit" class="btn" value="'.cplang('search').'" onclick="return srchforum()" /></div>';
		showformfooter();
		showtablefooter();

		showtableheader();
		exit;
	}
	
	$master		= C::t( 'master_main' )->fetch( $mid );
	if( !$master ){
		cpmsg( '您选择的内容不存在', '', 'error' );
	}
	if( $do == 'list' ){
		if( submitcheck( 'ordersubmit' ) ){
			foreach( $_GET['order'] as $_id => $level ){
				C::t( 'master_works' )->update( $_id, array( 'order' => intval( $level ) ) );
			}
		}
		
		showtableheader();
		showformheader( "master&operation=work&do=list&mid={$mid}" );
		echo '<div style="height:30px;line-height:30px;">
				作品名称 <input class="txt" type="text" value="'.$_GET['name'].'" name="name" />
				<input type="submit" class="btn" value="'.cplang('search').'" onclick="return srchforum()" /></div>';
		showformfooter();
		showtablefooter();

		showtableheader();
		showformheader( "master&operation=work&do=list&mid={$mid}" );
		
		$_GET['page']	= $_GET['page'] ? $_GET['page'] : 1;
		$limit			= 10;
		$s_limit		= ( $_GET['page'] - 1 ) * $limit . ", {$limit}";
		$where			= "`a`.`mid` = '{$mid}'";
		$where			.= empty( $_GET['name'] ) ? '' : " AND `a`.`title` LIKE '%{$_GET['name']}%'";
		$memberLs		= C::t( 'master_works' )->fetch_all( $where, $s_limit, "`order` DESC, `id`" );
		$page			= multi( $memberLs['num'], $limit, $_GET['page'], ADMINSCRIPT."?action=master&operation=work&do=list" );

		showsubtitle( array( '排序', '作品名称', '玉雕名家', '摘要', 'admin' ) );
		foreach( $memberLs['list'] as $info ){
			showtablerow( '', '', array(
				"<input type='text' style='width:20px;' name='order[{$info['id']}]' value='{$info['order']}' />", 
				"<a href='./master.php?mid={$info['mid']}&id={$info['id']}' target='blank'>{$info['title']}</a>",
				"<a href='./master.php?id={$info['id']}' target='blank'>{$info['name']}</a>", 
				"<p style='width:600px;'>{$info['summary']}</p>",
				"<a href='./master.php?mod=work&op=info&mid={$info['mid']}&id={$info['id']}' target='blank'>浏览</a>&nbsp;" . 
				"<a href='./master.php?mod=work&op=mod&mid={$info['mid']}&id={$info['id']}' target='_blank'>{$lang[edit]}</a>&nbsp;" .
				"<a href='#' onclick=\"if( window.confirm( '您确定要删除该作品吗？' ) ) window.location='".ADMINSCRIPT."?action=master&operation=work&do=del&mid={$mid}&id={$info['id']}'\">删除</a>"
			));
		}
		showsubmit( 'ordersubmit' );
		showtablefooter();
		showtableheader();
		showtablerow( '', array( 'class="infobox"', 'class="infobox"' ), array( '', $page ) );
		showtablefooter();
	}elseif( $do == 'add' ){
		$master				= C::t( 'master_main' )->fetch( $_GET['mid'] );
		if( !$master ){
			cpmsg('您选择的内容不存在', '', 'error');
		}
		header( "Location:master.php?mod=work&op=add&mid={$_GET['mid']}" );
	}elseif( $do == 'del' ){
		if( empty( $_GET['id'] ) )
			showmessage( '请选择要删除的作品' );
		C::t( 'master_works' )->delete( $_GET['id'] );
		header( "Location:". ADMINSCRIPT."?action=master&operation=work&do=list&mid={$_GET['mid']}" );
	}elseif( $do == 'mod' ){
	}
}elseif( $opt == 'message' ){
	$dos		= array( 'list', 'add', 'del', 'mod' );
	$do			= in_array( $_GET['do'], $dos ) ? $_GET['do'] : array_shift( $opts );
	$mid		= $_GET['mid'];
	showsubmenu( '玉雕名家信息管理', array(
		array( '信息列表', "master&operation=message&do=list&mid={$mid}", 1 ),
		array( '添加信息', "master&operation=message&do=add&mid={$mid}", 0, 1 )
	));
	if( empty( $mid ) ){
		showtableheader();
		showformheader( "master&operation=message&do={$do}" );
		echo '<div style="height:30px;line-height:30px;">
				编号 <input class="txt" type="text" value="'.$_GET['name'].'" name="mid" />
				<input type="submit" class="btn" value="'.cplang('search').'" onclick="return srchforum()" /></div>';
		showformfooter();
		showtablefooter();

		showtableheader();
		exit;
	}
	
	$master		= C::t( 'master_main' )->fetch( $mid );
	if( !$master ){
		cpmsg( '您选择的内容不存在', '', 'error' );
	}
	if( $do == 'list' ){
		showtableheader();
		showformheader( "master&operation=message&do=list&mid={$mid}" );
		echo '<div style="height:30px;line-height:30px;">
				作品名称 <input class="txt" type="text" value="'.$_GET['name'].'" name="name" />
				<input type="submit" class="btn" value="'.cplang('search').'" onclick="return srchforum()" /></div>';
		showformfooter();
		showtablefooter();

		showtableheader();
		
		$_GET['page']	= $_GET['page'] ? $_GET['page'] : 1;
		$limit			= 10;
		$s_limit		= ( $_GET['page'] - 1 ) * $limit . ", {$limit}";
		$where			= "`a`.`mid` = '{$mid}'";
		$where			.= empty( $_GET['name'] ) ? '' : " AND `a`.`title` LIKE '%{$_GET['name']}%'";
		$memberLs		= C::t( 'master_message' )->fetch_all( $where, $s_limit, "`updtime` DESC, `id`" );
		$page			= multi( $memberLs['num'], $limit, $_GET['page'], ADMINSCRIPT."?action=master&operation=message&do=list&mid={$mid}" );

		showsubtitle( array( '文章标题', '玉雕名家', '摘要', '更新时间', 'admin' ) );
		foreach( $memberLs['list'] as $info ){
			showtablerow( '', '', array(
				"<a href='./master.php?mid={$info['mid']}&id={$info['id']}' target='blank'>{$info['title']}</a>",
				"<a href='./master.php?id={$info['id']}' target='blank'>{$info['name']}</a>", 
				"<p style='width:600px;'>{$info['summary']}</p>",
				$info['updtime'],
				"<a href='./master.php?mid={$info['mid']}&id={$info['id']}' target='blank'>浏览</a>&nbsp;" . 
				"<a href='./master.php?mod=message&op=mod&mid={$info['mid']}&id={$info['id']}' target='_blank'>{$lang[edit]}</a>&nbsp;" .
				"<a href='#' onclick=\"if( window.confirm( '您确定要删除该作品吗？' ) ) window.location='".ADMINSCRIPT."?action=master&operation=message&do=del&mid={$mid}&id={$info['id']}'\">删除</a>"
			));
		}
		
		showtablefooter();
		showtableheader();
		showtablerow( '', array( 'class="infobox"', 'class="infobox"' ), array( '', $page ) );
		showtablefooter();
	}elseif( $do == 'add' ){
		$master				= C::t( 'master_main' )->fetch( $_GET['mid'] );
		if( !$master ){
			cpmsg('您选择的内容不存在', '', 'error');
		}
		header( "Location:master.php?mod=message&op=add&mid={$_GET['mid']}" );
	}elseif( $do == 'del' ){
		if( empty( $_GET['id'] ) )
			showmessage( '请选择要删除的作品' );
		C::t( 'master_message' )->delete( $_GET['id'] );
		header( "Location:". ADMINSCRIPT."?action=master&operation=message&do=list&mid={$_GET['mid']}" );
	}elseif( $do == 'mod' ){
	}
}
?>